/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;

import java.time.Instant;


/**
 * 实现了将对象转换为Instant类型的转换器。
 * 该转换器专门用于将表示秒数的Long类型对象转换为Instant类型。
 */
public class InstantReplyConvertor implements Convertor<Instant> {
    /**
     * 将给定的对象转换为Instant类型。
     *
     * @param obj 待转换的对象，预期是一个Long类型的实例，表示自Unix纪元以来的秒数。
     * @return 返回一个Instant对象，表示与给定的秒数相对应的时间点。
     * @throws IllegalArgumentException 如果obj不是Long类型或其值代表的秒数超出Instant的范围，则抛出此异常。
     */
    @Override
    public Instant convert(Object obj) {
        // 使用Long类型的安全转换，确保obj是一个Long实例。
        return Instant.ofEpochSecond((Long) obj);
    }
}
